package io2.nio.pipeline2;

public class Test {
    public static void main(String[] args) {
        Pipeline pipeline = new Pipeline();
        pipeline.addLast(new Handler() {
            @Override
            public void read(HandlerContext context, String obj) {
                obj = obj + "handler1... ";
                System.out.println(obj);
                context.read(obj);
            }

            @Override
            public void write(HandlerContext context, String obj) {
                obj = obj + "handler1... ";
                System.out.println(obj);
                context.write(obj);
            }
        });
        pipeline.addLast(new Handler() {
            @Override
            public void read(HandlerContext context, String obj) {
                obj = obj + "handler2... ";
                System.out.println(obj);
                context.read(obj);
            }

            @Override
            public void write(HandlerContext context, String obj) {
                obj = obj + "handler2... ";
                System.out.println(obj);
                context.write(obj);
            }
        });
        pipeline.addLast(new Handler() {
            @Override
            public void read(HandlerContext context, String obj) {
                obj = obj + "handler3... ";
                System.out.println(obj);
                context.read(obj);
            }

            @Override
            public void write(HandlerContext context, String obj) {
                obj = obj + "handler3... ";
                System.out.println(obj);
                context.write(obj);
            }
        });
        pipeline.fireRead("Hello, world!");
        System.out.println("============================");
        pipeline.fireWrite("Bye, Bye!");
    }
}
